﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Text;

namespace WebApplication
{
    public partial class Default : System.Web.UI.Page
    {
        Framework framework = new Framework();

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected string GetMenu()
        {
            var resources = framework.Resources.ToList();
            var root = resources.Where(x => !x.PID.HasValue).ToList();
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            root.ForEach(x =>
            {
                sb.Append("{ name: \"").Append(x.Name).Append("\",icon:\"");
                sb.Append(string.IsNullOrEmpty(x.IconUrl) ? "Themes/Default/images/ui-icon_home.gif" : x.IconUrl).Append("\",items:[");
                var children = resources.Where(w => w.PID == x.ID).ToList();
                children.ForEach(c =>
                {
                    sb.Append("{ name: \"").Append(c.Name).Append("\",icon:\"");
                    sb.Append(string.IsNullOrEmpty(c.IconUrl) ? "" : c.IconUrl).Append("\",url:\"").Append(c.Url).Append("\"},");
                });
                sb.Append("]},");
            });
            sb.Append("]");
            return sb.ToString();
        }
    }
}